package com.tedu.ivos.geofence.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tedu.ivos.base.response.JsonResult;
import com.tedu.ivos.geofence.pojo.dto.GeofenceQuery;
import com.tedu.ivos.geofence.pojo.dto.GeofenceSaveParam;
import com.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import com.tedu.ivos.geofence.service.GeofenceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "电子围栏模块")
@Slf4j
@RestController
@RequestMapping("/v1/geofence/")
public class GeofenceController {

    @Autowired
    private GeofenceService geofenceService;

    @ApiOperation(value = "查询电子围栏信息")
    @ApiOperationSupport(order = 10)
    @GetMapping("select")
    public JsonResult selectGeofence(GeofenceQuery geofenceQuery) {
        log.debug("查询电子围栏信息,参数:{}", geofenceQuery);
        List<GeofenceVO> geofenceVO = geofenceService.selectGeofence(geofenceQuery);

        return JsonResult.ok(geofenceVO);
    }

    @ApiOperation(value = "删除围栏")
    @ApiOperationSupport(order = 20)
    @DeleteMapping("delete/{id}")
    public JsonResult deleteGeofence(@PathVariable Long id) {
        log.debug("删除围栏，参数：{}", id);
        geofenceService.deleteGeofence(id);

        return JsonResult.ok();
    }

    @ApiOperation(value = "保存围栏")
    @ApiOperationSupport(order = 30)
    @PostMapping("save")
    public JsonResult saveGeofence(GeofenceSaveParam geofenceSaveParam){
        log.debug("保存围栏，参数：{}", geofenceSaveParam);
        geofenceService.saveGeofence(geofenceSaveParam);

        return JsonResult.ok();
    }
}
